package cn.iocoder.yudao.module.infra.tts.impl.proxy;

import cn.hutool.core.util.StrUtil;
import cn.iocoder.yudao.module.infra.tts.ITTSApi;
import cn.iocoder.yudao.module.infra.tts.impl.SimpleTTSApi;

public class ProxyTTS extends SimpleTTSApi {
    private final ITTSApi ttsApi;

    public ProxyTTS(ITTSApi ttsApi) {
        this.ttsApi = ttsApi;
    }

    @Override
    public String createCloneVoice(String url) {
        return ttsApi.createCloneVoice(url);
    }

    @Override
    public byte[] convertTextToSpeech(Integer audioToneId, String cloneVoiceId, String voice, String voice_path, String voice_hash, String voice_suffix, String response_format, String input) {
        if (StrUtil.isEmpty(cloneVoiceId)){
            throw new IllegalArgumentException("cloneVoiceId is empty");
        }

        if (input != null) {
            input = input.replace("操", "肏");
        }
        return ttsApi.convertTextToSpeech(audioToneId, cloneVoiceId, voice, voice_path, voice_hash, voice_suffix, response_format, input);
    }

    @Override
    public byte[] convertTextToSpeech(String voice, String voice_path, String voice_hash, String voice_suffix, String response_format, String input) {
        if (input != null) {
            input = input.replace("操", "肏");
        }

        return ttsApi.convertTextToSpeech(voice, voice_path, voice_hash, voice_suffix, response_format, input);
    }

}
